package com.c.ctgproject.adapter.guang

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapterV2
import com.c.ctgproject.base.BaseRecyclerViewAdapter
import com.c.ctgproject.entity.guang.PartSelectEntity
import com.c.ctgproject.utils.handlerNull

class PartSelectAdapter(private val context: Context, private val mList: ArrayList<PartSelectEntity.DataBean>, private val listener: PartSelectAdapterListener) : BaseRecyclerViewAdapter(context, mList) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_part_select_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = mList[position]
            holder.mCheckBox.isChecked=data.isSelect
            holder.mTextView.text = data.name.handlerNull()
            holder.mParentLL.setOnClickListener {
                holder.mCheckBox.performClick()
            }
            holder.mCheckBox.setOnClickListener {
                listener.onItemSelect(position,holder.mCheckBox.isChecked)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mTextView: TextView = view.findViewById(R.id.mTextView)
        val mParentLL: LinearLayout = view.findViewById(R.id.mParentLL)
        val mCheckBox: CheckBox = view.findViewById(R.id.mCheckBox)
    }

    interface PartSelectAdapterListener {
        fun onItemSelect(position: Int,select:Boolean)
    }

}